<?php
require_once 'BaseController.php';

/**
 * 【PC版】トップページ コントローラ
 */
class Renew_TopController extends Renew_BaseController
{

    /**
     * メインアクション
     */
    public function indexAction()
    {
        $params = $this->getParameters();

        // エリアコード名
        $this->_data['area_code_name_hokkaido'] = Apm_Config_Common::AREA_CODE_NAME_HOKKAIDO;
        $this->_data['area_code_name_tohoku'] = Apm_Config_Common::AREA_CODE_NAME_TOHOKU;
        $this->_data['area_code_name_kanto'] = Apm_Config_Common::AREA_CODE_NAME_KANTO;
        $this->_data['area_code_name_koshinetsu_hokuriku'] = Apm_Config_Common::AREA_CODE_NAME_KOSHINETSU_HOKURIKU;
        $this->_data['area_code_name_tokai'] = Apm_Config_Common::AREA_CODE_NAME_TOKAI;
        $this->_data['area_code_name_kansai'] = Apm_Config_Common::AREA_CODE_NAME_KANSAI;
        $this->_data['area_code_name_chugoku_shikoku'] = Apm_Config_Common::AREA_CODE_NAME_CHUGOKU_SHIKOKU;
        $this->_data['area_code_name_kyushu_okinawa'] = Apm_Config_Common::AREA_CODE_NAME_KYUSHU_OKINAWA;

        switch ($params['Category'])
        {
            case Apm_Config_Common::AREA_CODE_NAME_TOHOKU:
                $tpl = "tohoku";
                break;
            case Apm_Config_Common::AREA_CODE_NAME_KANTO:
                $tpl = "kanto";
                break;
            case Apm_Config_Common::AREA_CODE_NAME_TOKAI:
                $tpl = "tokai";
                break;
            case Apm_Config_Common::AREA_CODE_NAME_KANSAI:
                $tpl = "kansai";
                break;
            case Apm_Config_Common::AREA_CODE_NAME_CHUGOKU_SHIKOKU:
                $tpl = 'chugoku';
                break;
            case Apm_Config_Common::AREA_CODE_NAME_KOSHINETSU_HOKURIKU:
                $tpl = 'hokuriku';
                break;
            case Apm_Config_Common::AREA_CODE_NAME_KYUSHU_OKINAWA:
                $tpl = 'kyushu';
                break;
            default:
                $tpl = 'zenkoku';
                break;
        }
        // 全国の物件数取得
        $this->_data['zenkokucnt'] = number_format(Apm_Util::getZenkokuCount());
        // エリア毎のテンプレートを設定
        $this->_data['tab_contents'] = $this->getApmHelper($tpl)->getBlock($this->_data);
        // $this->_data['Shinchaku'] = $this->getShinchaku(); //20150124コメント

        // ★★★人気エリア
        $ninkiparams = array();
        $ninkiparams['listCount'] = 20;
        $data = array();

        $model = new Search_Model_Selsikucyoson();
        $data = $model->getNinkiShikucyosonData($ninkiparams);
        $items = array();
        foreach ($data as $d)
        {
            $d['PrefName'] = $this->getPrefName($d['TODOUFUKEN_CD']);
            $items[] = $d;
        }
        $this->_data['ninkiArea'] = $items;
        // ★★★人気エリア

        // ★★★人気駅
        $ekiparams = array();
        $ekiparams['listCount'] = 20;
        $ekidata = array();
        $ekimodel = new Search_Model_Seleki();
        $ekidata = $ekimodel->getNinkiShikuchousonData($ekiparams);
        $ekiitems = array();
        foreach ($ekidata as $d)
        {
            $d['PrefName'] = $this->getPrefName($d['TODOUFUKEN_CD']);
            $ekiitems[] = $d;
        }
        $this->_data['ninkiEki'] = $ekiitems;
        // ★★★人気駅

        $this->displayBody('index', 'topbar1');
    }

    /**
     * 新着物件取得
     *
     * @return 新着物件
     */
    private function getShinchaku()
    {
        $model = new Renew_Model_Shinchaku();
        return $model->getShinchakuBlockData(5);
    }

    /**
     * SEO対策用のmetaタグに配置する文章を設定
     */
    protected function setSeoMeta()
    {
        $this->_alternate_url = 'sp/';

        $params = $this->getParameters();

        // 北海道以外の場合に遷移してくるので、単純変換でOK
        if (in_array($params['Category'], Apm_Config_Search::$AREA_NAME_CODE_LIST))
        {
            $word = Apm_Config_Search::$AREA_CODE_NAME_JP_LIST[$params['Category']];

            $this->_meta_title = $word . 'の賃貸物件を探す 【アパマンショップ】';
            $this->_meta_description = $word . 'のお部屋を探すなら、不動産情報が満載のアパマンショップネットワーク。賃貸マンション・アパートなど、';
            $this->_meta_keywords = $word . ' 賃貸,賃貸';
            $this->_alternate_url = 'sp/' . $params['Category'] . '/';
        }
    }

}
?>
